import random

# def bubble_sort(li):
#     for i in range(len(li)-1):
#         exc = False
#         for j in range(len(li)-i-1):
#             if li[j] < li[j+1]:
#                 li[j],li[j+1] = li[j+1],li[j]
#                 exc = True
#         print(li)
#         if not exc:
#             return
#
# li = [random.randint(0,10000) for i in range(10)]
# print(li)
# bubble_sort(li)

def bubble_sort(li):
    for i in range(len(li)-1):
        exc = False
        for j in range(len(li) - i - 1):
            if li[j] > li[j+1]:
                li[j],li[j+1] = li[j+1],li[j]
                exc = True
        if not exc:
            return
    return li


li = [3,4,1,5,7,2,]
print(bubble_sort(li))